package com.tanhua.dubbo.api.mongo;

import com.tanhua.domain.mongo.TestQuestion;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@Service
public class TestQuestionApiImpl implements TestQuestionApi {

    @Autowired
    private MongoTemplate mongoTemplate;
    @Override
    public void save(TestQuestion question) {
        mongoTemplate.save(question);
    }

    @Override
    public List<TestQuestion> findAll() {
        Query query = new Query();
        return mongoTemplate.find(query, TestQuestion.class);
    }

    //根据id查询试卷
    @Override
    public List<TestQuestion> findByPaperId(Integer type) {
        Query query = new Query(Criteria.where("followerPaper").is(type));
        List<TestQuestion> questionList = mongoTemplate.find(query, TestQuestion.class);

        return questionList;
    }
}
